<template>
  <div>
    <el-table border :data="list">
      <el-table-column prop="roleId" label="角色ID"/>
      <el-table-column prop="roleName" label="角色名称"/>
      <el-table-column prop="roleCode" label="角色标识"/>
      <el-table-column label="操作">
        <template slot-scope="{row}">
          <el-button @click="remove(row)" type="danger" size="mini">删除</el-button>
        </template>
      </el-table-column>

    </el-table>
  </div>
</template>

<script>

export default {
  name: 'Home',
  data() {
    return {
      list:[]
    }
  },
  mounted() {
    this.query();
  },
  methods:{
    query(){
      this.$http.get('http://localhost:8081/api/sys/role/').then(res => {
        if (res.data.code === 0) {
          this.list = res.data.data;
        } else {
          this.$message.error(res.data.msg);
        }
      }).catch(e => {
        this.$message.error(e.message);
      });
    },
    remove(row) {
      this.$http.delete('https://v1.eleadmin.com/api/sys/role/' + row.roleId).then(res => {
        if (res.data.code === 0) {
          this.$message({message: res.data.msg, type: 'success'});
          this.query();
        } else {
          this.$message.error(res.data.msg);
        }
      }).catch(e => {
        this.$message.error(e.message);
      });
    }
  }
}
</script>
